#include "widget.h"
#include "factory.h"

#include <iostream>

using namespace std;

class Client
{
public:
	Client()
	{
		m_pWindow = NULL;
		m_pScrollBar = NULL;
	}

	~Client()
	{
		if(m_pWindow) {		delete m_pWindow;		m_pWindow = NULL; }
		if(m_pScrollBar) {	delete m_pScrollBar;	m_pScrollBar = NULL; }
	}

public:
	void createWidget(WidgetFactory* pFact)
	{
		m_pWindow = pFact->createWindow();
		m_pScrollBar = pFact->createScrollBar();
	}

	void show()
	{
		m_pWindow->show();
		m_pScrollBar->show();
	}

	bool check()
	{
		if(m_pWindow != NULL && m_pScrollBar != NULL) {
			return true;
		} 
		else {
			return false;
		}
	}

private:
	Window* m_pWindow;
	ScrollBar* m_pScrollBar;
};

int main()
{
	Client pmClient, motifClient;

	WidgetFactory* pPMFact = new PMWidgetFactory();
	WidgetFactory* pMotifFact = new MotifWidgetFactory();

	pmClient.createWidget(pPMFact);
	motifClient.createWidget(pMotifFact);

	if (pmClient.check())
	{
		pmClient.show();
	}
	if (motifClient.check())
	{
		motifClient.show();
	}

	if(pPMFact) {		delete pPMFact;		pPMFact = NULL; }
	if(pMotifFact) {	delete pMotifFact;	pMotifFact = NULL; }

	return 0;
}